<?php

include '../config/config.php';
include 'Zend/Db.php';  

$db = Zend_Db::factory('Pdo_Mysql', $dbConfig);

extract($_POST);

$review_id = $db->fetchOne("SELECT * FROM reviews WHERE entry_id = '$entry_id'");

$review_insert = array(
	'review_id'		=> '',
	'entry_id'		=> $entry_id,
	'review'		=> $review,
	'flagged'		=> $flagged,
	'reviewed'		=> $reviewed,
	'fk_entry_id'	=> 0
);

$review_update = array(
	'review'		=> $review,
	'flagged'		=> $flagged,
	'reviewed'		=> $reviewed,
	'fk_entry_id'	=> 0
);

if ($review_id > 0) {
	$db->update('reviews', $review_update, "review_id = $review_id");
	echo ' Review successfully updated: ' .  date("l jS F o @ H:i:s");
}
else {
	$db->insert('reviews', $review_insert);
	$review_id = $db->lastInsertId();
	echo ' Review successfully inserted: ' .  date("l jS F o @ H:i:s");
}

?>